package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/yuewen/config"
	"net/http"
	"net/url"
)

type UserGetUserInfoApiService service

type GetUserInfoRequest struct {
	ctx        context.Context
	ApiService *UserGetUserInfoApiService
	startTime  *uint64
	endTime    *uint64
	page       *int
	appFlag    *string
	openId     *string
	nextId     *string
}

type UserGetUserInfoResponse struct {
	Code    *int64        `json:"code,omitempty"`
	Message *string       `json:"message,omitempty"`
	Data    *UserListData `json:"data,omitempty"`
}

type UserListData struct {
	TotalCount *uint       `json:"total_count,omitempty"`
	NextId     *string     `json:"next_id,omitempty"`
	List       []*UserInfo `json:"list,omitempty"`
}

type UserInfo struct {
	AppFlag           *string           `json:"appflag,omitempty"`
	AreaName          *string           `json:"area_name,omitempty"`
	AppName           *string           `json:"app_name,omitempty"`
	OpenId            *string           `json:"openid,omitempty"`
	GuId              *string           `json:"guid,omitempty"`
	NickName          *string           `json:"nickname,omitempty"`
	ChargeAmount      *uint             `json:"charge_amount,omitempty"`
	ChargeNum         *uint             `json:"charge_num,omitempty"`
	CreateTime        *string           `json:"create_time,omitempty"`
	SeqTime           *string           `json:"seq_time,omitempty"`
	RefluxTime        *string           `json:"reflux_time,omitempty"`
	SubscribeTime     *string           `json:"subscribe_time,omitempty"`
	VipEndTime        *string           `json:"vip_end_time,omitempty"`
	IsSubscribe       *int              `json:"is_subscribe,omitempty"`
	Sex               *int              `json:"sex,omitempty"`
	ChannelId         *uint             `json:"channel_id,omitempty"`
	OriginalChannelId *string           `json:"original_channel_id,omitempty"`
	ChannelName       *string           `json:"channel_name,omitempty"`
	BookId            *string           `json:"book_id,omitempty"`
	BookName          *string           `json:"book_name,omitempty"`
	UpdateTime        *string           `json:"update_time,omitempty"`
	OsType            *string           `json:"os_type,omitempty"`
	Manufacturer      *string           `json:"manufacturer,omitempty"`
	WxVersion         *string           `json:"wx_version,omitempty"`
	ExternalUserInfo  *ExternalUserInfo `json:"external_userinfo,omitempty"`
}

type ExternalUserInfo struct {
	CorpId         *string `json:"corp_id,omitempty"`
	KfId           *string `json:"kf_id,omitempty"`
	ExternalUserId *string `json:"external_userid,omitempty"`
}

func (r *GetUserInfoRequest) StartTime(startTime uint64) *GetUserInfoRequest {
	r.startTime = &startTime
	return r
}

func (r *GetUserInfoRequest) EndTime(endTime uint64) *GetUserInfoRequest {
	r.endTime = &endTime
	return r
}

func (r *GetUserInfoRequest) Page(page int) *GetUserInfoRequest {
	r.page = &page
	return r
}

func (r *GetUserInfoRequest) AppFlag(appFlag string) *GetUserInfoRequest {
	r.appFlag = &appFlag
	return r
}

func (r *GetUserInfoRequest) OpenId(openId string) *GetUserInfoRequest {
	r.openId = &openId
	return r
}

func (r *GetUserInfoRequest) NextId(nextId string) *GetUserInfoRequest {
	r.nextId = &nextId
	return r
}

func (r *GetUserInfoRequest) Execute() (*UserGetUserInfoResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *GetUserInfoRequest) ApiSecret(ApiSecret string) *GetUserInfoRequest {
	r.ctx = context.WithValue(r.ctx, config.ApiSecret, ApiSecret)
	return r
}

func (r *GetUserInfoRequest) Email(Email string) *GetUserInfoRequest {
	r.ctx = context.WithValue(r.ctx, config.Email, Email)
	return r
}

func (r *GetUserInfoRequest) WithLog(enable bool) *GetUserInfoRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *UserGetUserInfoApiService) Get(ctx context.Context) *GetUserInfoRequest {
	return &GetUserInfoRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *UserGetUserInfoApiService) getExecute(r *GetUserInfoRequest) (*UserGetUserInfoResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/" + cfg.Prefix + "/User/GetUserInfo"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *UserGetUserInfoResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasAppFlag(r.appFlag); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	localVarQueryParams.Add("appflag", *r.appFlag)

	if r.startTime != nil {
		localVarQueryParams.Add("start_time", toString(r.startTime))
	}

	if r.endTime != nil {
		localVarQueryParams.Add("end_time", toString(r.endTime))
	}

	if r.page != nil {
		localVarQueryParams.Add("page", toString(r.page))
	}

	if r.openId != nil {
		localVarQueryParams.Add("openid", *r.openId)
	}

	if r.nextId != nil {
		localVarQueryParams.Add("next_id", *r.nextId)
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
